#!/bin/bash

set -o errexit
export LC_ALL=C

for GENOME_ID in `cut -f1 other_systems/genomes_grp1.txt | head -n1`; do
    echo $GENOME_ID
    6_annotation/prepare4new_org.sh $GENOME_ID 
done


for GENOME_ID in `cut -f1 other_systems/genomes_grp1.txt | head -n30`; do
    echo $GENOME_ID
    mpirun -q quad -np 1 ~/runner 6_annotation/prepare4new_org.sh $GENOME_ID
    sleep 1
done


##
## Quad
##
for GENOME_ID in \
    `join -v1 <(ls ~/work/data/annotation_cluster_done_internal_quad/) <(cat <(ls ~/work/data/annotation_cluster) <(ls ~/work/data/annotation_cluster_done_external/) | sort) | head -n7`; do

    echo $GENOME_ID;
    mpirun -q quad -np 1 ~/runner 6_annotation/prepare4new_org.sh $GENOME_ID;
    sleep 3600;
done

##
## Fs
##
for GENOME_ID in `cut -f1 other_systems/genomes_grp2.txt | tail -n+33 | head -n2`; do
    echo $GENOME_ID;
    mpirun -q fs -np 1 ~/runner 6_annotation/prepare4new_org_fs.sh $GENOME_ID;
    sleep 3600;
done


#for i in {01..10}; do h=quad$i; echo $h; ssh $h 'rm -rf /tmp/mixagol/annotation_cluster/'; done

for d in ~/work/data/annotation_cluster/NC_*; do echo -e $d"\t"$(ls $d/src_faa | wc -l)"\t"$(ls $d/src | wc -l); done
for i in {01..10}; do h=quad$i; echo $h; ssh $h 'ps axu | grep mixagol | grep runner | grep -v grep | wc -l'; done
for i in {01..10}; do h=quad$i; echo $h; ssh $h 'df -h /tmp | grep dev'; done


# full
# find $AN_DIR/src_faa/ -type f -name "*.faa" | sort | xargs -n1 -P1 -I {} bash -c "cat {} | 6_annotation/annotate_wu_nw_simple.sh $AN_DIR && rm {}"

# restrict
# find $AN_DIR/ -maxdepth 1 -type d -name "annot_*" | sort | xargs -n1 -P1 6_annotation/annotate_wu_nw_simple_restrict.sh


cat ~/data//6_annotation/20120802/a.laidlawii_wunw/results_go_exact.txt | cut -f4 | awk '{print $1}'     | awk '{if ($1>10) {print 0} else print $1}'     | sort | uniq -c | 9_annotation_analysis/analize_annotation.py --tsv


for d in ~/data/6_annotation/20120802/annotation_cluster_done_external/NC_*; do
    echo -e $(basename $d)"\t"$(cat $d/results_go_exact.txt | cut -f3 | awk '{print $1}'     | awk '{if ($1>10) {print 0} else print $1}'     | sort | uniq -c | 9_annotation_analysis/analize_annotation.py --tsv)
done

for d in ~/work/data/annotation_cluster/NC_*; do
    echo -e $d"\t"$(cat $d/worker_hostname)"\t"$(ls $d | grep nw_external_mk | wc -l)"\t"$(ls $d/src_faa | wc -l)"\t"$(ls $d/src | wc -l)"\t"$(ls $d | grep ann | wc -l)"\t"$(ssh $(cat $d/worker_hostname) 'ps ax | grep '"$(basename $d)"' | grep -v grep | wc -l')"\t"$(($(date +%s) - $(stat $d/$(ls $d | grep ann | tail -n1) -c %Y)))"\t"$(cat $d/speed.dump | cut -f3 | awk '{S+=$1}END{printf("%.1f", S/NR*12)}')
done


for d in ~/work/data/annotation_cluster/NC_*; do echo -e $d"\t"$(cat $d/worker_hostname)"\t"$(ls $d | grep nw_external_mk | wc -l)"\t"$(ls $d/src_faa | wc -l)"\t"$(ls $d/src | wc -l)"\t"$(ls $d | grep ann | wc -l)"\t"$(ssh $(cat $d/worker_hostname) 'ps ax | grep '"$(basename $d)"' | grep -v grep | wc -l')"\t"$(($(date +%s) - $(stat $d/$(ls $d | grep ann | tail -n1) -c %Y)))"\t"$(cat $d/speed.dump | tail -n 100 | cut -f3 | awk '{S+=$1}END{printf("%.1f", S/NR*12)}'); done 2>/dev/null


